package com.payment.ktb.activity.main4;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.payment.ktb.Interface.HttpCallbackListener;
import com.payment.ktb.R;
import com.payment.ktb.activity.BaseActivity;
import com.payment.ktb.constants.HttpActions;
import com.payment.ktb.constants.HttpUrls;
import com.payment.ktb.utils.AlertDialogUtils;
import com.payment.ktb.utils.HttpUtils;
import com.payment.ktb.view.BadgeView;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by admin on 2017/9/29.
 */

public class AgentStatDay extends BaseActivity {



    @BindView(R.id.rl_agentstatday_message)
    RelativeLayout rl_agentstatday_message;
    @BindView(R.id.tv_agentstatday_dayProfit)
    TextView tv_agentstatday_dayProfit;
    @BindView(R.id.tv_agentstatday_payCount)
    TextView tv_agentstatday_payCount;
    @BindView(R.id.tv_agentstatday_paySumPrice)
    TextView tv_agentstatday_paySumPrice;
    @BindView(R.id.tv_agentstatday_allProfit)
    TextView tv_agentstatday_allProfit;
    @BindView(R.id.tv_agentstatday_dayOrg)
    TextView tv_agentstatday_dayOrg;
    @BindView(R.id.tv_agentstatday_childOrgCount)
    TextView tv_agentstatday_childOrgCount;
    @BindView(R.id.tv_agentstatday_passUser)
    TextView tv_agentstatday_passUser;
    @BindView(R.id.tv_agentstatday_regUser)
    TextView tv_agentstatday_regUser;

    @BindView(R.id.iv_agentstatday_medal1)
    ImageView iv_agentstatday_medal1;
    @BindView(R.id.iv_agentstatday_medal2)
    ImageView iv_agentstatday_medal2;
    @BindView(R.id.iv_agentstatday_medal3)
    ImageView iv_agentstatday_medal3;
    @BindView(R.id.iv_agentstatday_medal4)
    ImageView iv_agentstatday_medal4;
    @BindView(R.id.tv_agentstatday_agentlevel)
    TextView tv_agentstatday_agentlevel;





    BadgeView badgeView;
    int page = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_agentstatday);
        ButterKnife.bind(this);
        initData();
    }



    private void initData() {

        //设置badgeview
        badgeView = new BadgeView(mContext);
        badgeView.setTargetView(rl_agentstatday_message);
        badgeView.setTextColor(getResources().getColor(R.color.red));
        badgeView.setBackground(10,getResources().getColor(R.color.white));
        badgeView.setTextSize(8);
        badgeView.setBadgeCount(getIntent().getIntExtra("unReadMsg",0));
        tv_agentstatday_dayProfit.setText("¥ " + getIntent().getDoubleExtra("dayProfit",0));
        tv_agentstatday_payCount.setText(getIntent().getStringExtra("payCount"));
        tv_agentstatday_paySumPrice.setText("¥ " + getIntent().getDoubleExtra("paySumPrice",0));
        tv_agentstatday_allProfit.setText("¥ " + getIntent().getDoubleExtra("allProfit",0));
        tv_agentstatday_dayOrg.setText(getIntent().getStringExtra("dayOrg"));
        tv_agentstatday_childOrgCount.setText(getIntent().getStringExtra("childOrgCount"));
        tv_agentstatday_passUser.setText(getIntent().getStringExtra("passUser"));
        tv_agentstatday_regUser.setText(getIntent().getStringExtra("regUser"));



        //L33 经销商 *
        //L31 一级代理 **
        //L30 办事处 ***
        //其它 ****
        String orgType = getIntent().getStringExtra("orgType");
        if (orgType.equals("L33")) {
            iv_agentstatday_medal1.setVisibility(View.GONE);
            iv_agentstatday_medal3.setVisibility(View.GONE);
            iv_agentstatday_medal4.setVisibility(View.GONE);
            tv_agentstatday_agentlevel.setText("代理级别：经销商");
        }else if (orgType.equals("L31")) {
            iv_agentstatday_medal3.setVisibility(View.GONE);
            iv_agentstatday_medal4.setVisibility(View.GONE);
            tv_agentstatday_agentlevel.setText("代理级别：一级代理");

        }else if (orgType.equals("L30")) {
            iv_agentstatday_medal4.setVisibility(View.GONE);
            tv_agentstatday_agentlevel.setText("代理级别：办事处");

        }else {
            tv_agentstatday_agentlevel.setText("代理级别：内部员工");

        }



    }



    @OnClick({R.id.rl_agentstatday_message,R.id.ll_agentstatday_title_back,R.id.ll_agentstatday_salestatistics,R.id.ll_agentstatday_customermanage,R.id.ll_agentstatday_agentmanage,R.id.ll_agentstatday_ordermanage,R.id.ll_agentstatday_profitmanage,R.id.btn_agentstatday_dayProfit})
    public void clickEvent(View view) {
        Intent intent = null;

        switch (view.getId()) {

            case R.id.rl_agentstatday_message:
                getAgentMsg();
                break;

            //销售统计
            case R.id.ll_agentstatday_salestatistics:
                intent = new Intent(mContext,SaleStatisticsActivity.class);
                startActivity(intent);
                break;

            //商户管理
            case R.id.ll_agentstatday_customermanage:
                intent = new Intent(mContext,CustomerManageActivity.class);
                startActivity(intent);
                break;

            //代理管理
            case R.id.ll_agentstatday_agentmanage:
                intent = new Intent(mContext,AgentManageActivity.class);
                startActivity(intent);
                break;

            //订单管理
            case R.id.ll_agentstatday_ordermanage:
                intent = new Intent(mContext,OrderManageActivity.class);
                startActivity(intent);
                break;

            //订单管理
            case R.id.ll_agentstatday_profitmanage:
                intent = new Intent(mContext,ProfitManageActivity.class);
                startActivity(intent);
                break;

            //提现
            case R.id.btn_agentstatday_dayProfit:
                intent = new Intent(mContext,ProfitWithdrawActivity.class);
                startActivity(intent);
                break;

            //返回
            case R.id.ll_agentstatday_title_back:
                finish();
                break;


        }

    }


    //获取代理商消息
    public void getAgentMsg() {

        progressDialogUtils.showProgress();

        //构造传输参数
        Map<String, String> map = new HashMap<String,String>();
        map.put("page", String.valueOf(page));

        //向服务器发送请求
        HttpUtils.HttpRequestByVollery(HttpUrls.URL, HttpActions.OrgMsgList, map, mQueue, new HttpCallbackListener() {
            @Override
            public void onFinish(String response) {
                progressDialogUtils.dismissProgress();
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    Intent intent = new Intent(mContext,AgentMsgActivity.class);
                    intent.putExtra("records",jsonObject.optString("records"));
                    startActivity(intent);


                } catch (JSONException e) {
                    e.printStackTrace();
                    AlertDialogUtils.showAlertDialog(mContext, getResources().getString(R.string.json_parse_error));
                }
            }

            @Override
            public void onError(VolleyError volleyError) {
                progressDialogUtils.dismissProgress();
                AlertDialogUtils.showAlertDialog(mContext, volleyError.getMessage());
            }
        });
    }
}
